## Fig2: Capacity function, C(p)

from PyM import *

# Important points
O = (0,0); X = (1,0); Y = (0,1); U = (1,1); Xh=(0.5,0); Yh=(0.5,1)

L = np.log2

t = ls(0.001,0.999,100)
def C(p): return 1+p*L(p)+(1-p)*L(1-p)
def P(x): return 4*(x**2-x)+1

# plotting
close('all')

eps=0.1
ax = plt.figure("Figure 2: The capacity function", figsize=(4,4))
plt.xlim(-eps,1+eps)
plt.ylim(-eps,1+eps)
plt.axis('off')

seg(O,X)
seg(O,Y)
seg(Y,U); seg(X,U); seg(Xh,Yh)

plot(t,C(t),lw=2,color='blue')
plot(t,P(t),lw=1,color='red',linestyle='--')

# labeling

lable(O,'0',dx=-0.7*eps,dy=-eps, fs='14')
lable(Xh,'1/2',dx=-0.7*eps,dy=-eps, fs='14')
lable(X,'1',dx=-0.4*eps,dy=-eps, fs='14')


lable(Y,'1',dx=-eps,dy=-0.2*eps, fs='14')

plt.show()
